/*
 * PanelTowerSettingsDouble.java
 *
 * Created on January 15, 2008, 1:21 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package hextd.tower;

import hextd.core.ContextNormal;

/**
 *
 * @author  hylke
 */
public class PanelTowerSettingsDouble extends PanelTowerSettings {

	private String[] modes1;
	private String[] modes2;
	private int mode1 = 0;
	private int mode2 = 0;
	private Tower t;
	private ContextNormal c;
	private boolean loading = false;
	private boolean enabled = true;

	/** Creates new form PanelTowerSettingsDouble */
	public PanelTowerSettingsDouble(Tower t, ContextNormal c) {
		super();
		this.c = c;
		initComponents();
		this.t = t;
		this.setEnabled(enabled);
	}

	@Override
	public void setModes(int m, String[] modes) {
		if (m == 1) {
			this.loading = true;
			this.modes1 = modes;
			this.jComboBox_mode1.removeAllItems();
			for (int i = 0; i < this.modes1.length; i++) {
				this.jComboBox_mode1.addItem(this.modes1[i]);
			}
			this.jComboBox_mode1.setSelectedIndex(this.mode1);
			this.jLabel_mode1.setText(this.modes1[this.mode1]);
			this.loading = false;
		} else if (m == 2) {
			this.loading = true;
			this.modes2 = modes;
			this.jComboBox_mode2.removeAllItems();
			for (int i = 0; i < this.modes2.length; i++) {
				this.jComboBox_mode2.addItem(this.modes2[i]);
			}
			this.jComboBox_mode2.setSelectedIndex(this.mode2);
			this.jLabel_mode2.setText(this.modes2[this.mode2]);
			this.loading = false;
		}
	}

	@Override
	public int getMode(int m) {
		if (m == 1) {
			return this.mode1;
		} else if (m == 2) {
			return this.mode2;
		}
		return -1;
	}

	@Override
	public void setMode(int m, int v, boolean suppress) {
		loading = suppress;
		if (m == 1) {
			mode1 = v;
			jComboBox_mode1.setSelectedIndex(mode1);
			jLabel_mode1.setText(modes1[mode1]);
			if (t.getMode(1) != mode1) {
				System.err.println("PanelTowerSettingsSingle::setMode tower and pts not synced?");
				//t.setMode(activateTick, 1, this.mode1);
			}
		} else if (m == 2) {
			mode2 = v;
			jComboBox_mode2.setSelectedIndex(mode2);
			jLabel_mode2.setText(modes2[mode2]);
			if (t.getMode(2) != mode2) {
				System.err.println("PanelTowerSettingsSingle::setMode tower and pts not synced?");
				//t.setMode(activateTick, 2, this.mode2);
			}
		}
		loading = false;
	}

	@Override
	public boolean isEnabled() {
		return this.enabled;
	}

	@Override
	public void setEnabled(boolean enable) {
		this.enabled = enable;
		this.jComboBox_mode1.setVisible(enable);
		this.jComboBox_mode2.setVisible(enable);
		this.jLabel_mode1.setVisible(!enable);
		this.jLabel_mode2.setVisible(!enable);
	}

	@Override
	public void setCanLock(boolean b) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jComboBox_mode1 = new javax.swing.JComboBox();
        jComboBox_mode2 = new javax.swing.JComboBox();
        jLabel_mode1 = new javax.swing.JLabel();
        jLabel_mode2 = new javax.swing.JLabel();

        setLayout(new java.awt.GridBagLayout());

        setBackground(this.c.colors.getColorBackGround());
        setForeground(this.c.colors.getColorForeGround());
        jLabel1.setBackground(this.c.colors.getColorBackGround());
        jLabel1.setForeground(this.c.colors.getColorForeGround());
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Target Modes");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel1, gridBagConstraints);

        jComboBox_mode1.setBackground(this.c.colors.getColorBackGround());
        jComboBox_mode1.setForeground(this.c.colors.getColorForeGround());
        jComboBox_mode1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox_mode1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_mode1ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.01;
        add(jComboBox_mode1, gridBagConstraints);

        jComboBox_mode2.setBackground(this.c.colors.getColorBackGround());
        jComboBox_mode2.setForeground(this.c.colors.getColorForeGround());
        jComboBox_mode2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox_mode2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox_mode2ActionPerformed(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jComboBox_mode2, gridBagConstraints);

        jLabel_mode1.setBackground(this.c.colors.getColorBackGround());
        jLabel_mode1.setForeground(this.c.colors.getColorForeGround());
        jLabel_mode1.setText("jLabel2");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel_mode1, gridBagConstraints);

        jLabel_mode2.setBackground(this.c.colors.getColorBackGround());
        jLabel_mode2.setForeground(this.c.colors.getColorForeGround());
        jLabel_mode2.setText("jLabel3");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.01;
        add(jLabel_mode2, gridBagConstraints);

    }// </editor-fold>//GEN-END:initComponents
    private void jComboBox_mode1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode1ActionPerformed
		if (!this.loading) {
			this.mode1 = this.jComboBox_mode1.getSelectedIndex();
			this.c.setMode(this.t, 1, this.mode1);
		}
    }//GEN-LAST:event_jComboBox_mode1ActionPerformed

    private void jComboBox_mode2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox_mode2ActionPerformed
		if (!this.loading) {
			this.mode2 = this.jComboBox_mode2.getSelectedIndex();
			this.c.setMode(this.t, 2, this.mode2);
		}
    }//GEN-LAST:event_jComboBox_mode2ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox_mode1;
    private javax.swing.JComboBox jComboBox_mode2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel_mode1;
    private javax.swing.JLabel jLabel_mode2;
    // End of variables declaration//GEN-END:variables
}
